package com.briup.facade.web.controller;

import com.briup.common.web.Message;
import com.briup.common.web.MessageUtil;
import com.briup.common.web.SecurityUtil;
import com.briup.logging.annotation.LoggingAccess;
import com.briup.operator.entity.Category;
import com.briup.operator.service.ICategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@LoggingAccess("算子分类模块")
@RestController
@Api(tags = "算子分类模块")
public class OperatorCategoryController {

    @Autowired
    private ICategoryService categoryService;

    // 查找所有算子分类
    @LoggingAccess("查找所有算子分类")
    @ApiOperation(value = "查看所有算子分类")
    @GetMapping("/operateCategory/")
    public Message findAll(){
        List<Category> categoryList = categoryService.findAll();
        return MessageUtil.success(categoryList);
    }
    // 查看算子分类详情
    @LoggingAccess("查看算子分类详情")
    @GetMapping("/operateCategory/{id}")
    @ApiOperation(value = "查看算子分类详情",notes = "此处没有级联查询")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id",value = "算子分类id",paramType = "path",dataType = "int",required = true)
    )
    public Message findById(@PathVariable("id") Integer id){
        Category category = categoryService.findById(id);

        return MessageUtil.success(category);
    }

    // 查看当前登录用户下的算子分类目录信息
    @LoggingAccess("当前登录用户下的算子分类目录信息")
    @ApiOperation(value = "查看当前登录用户下的算子分类目录信息",notes = "不需要参数")
    @GetMapping("/operateCategory/findByUser")
    public Message findCategoryByUserId() {
        List<Category> categoryList = categoryService.findCategoryByUserId(Integer.parseInt(SecurityUtil.getUserId()));
        return MessageUtil.success(categoryList);
    }
}
